package com.hzlj.position.locate.differentiation.positionWarningNotice;

import com.hzlj.common.message.common.dto.message.MessageNoticeResultDTO;
import com.hzlj.position.config.common.enums.ReportType;
import com.hzlj.position.locate.common.model.Position;
import com.hzlj.position.locate.differentiation.common.PositionWarningNoticeGzry;
import com.hzlj.position.locate.differentiation.common.PositionWarningNoticeJzry;
import com.hzlj.position.locate.differentiation.sysCheck.traceCheck.TraceSysCheckRouter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 默认
 */
@Slf4j
@Service
public class PositionWarningNoticeCommon extends PositionWarningNotice {

    @Resource
    private PositionWarningNoticeJzry positionWarningNoticeJzry;

    @Resource
    private PositionWarningNoticeGzry positionWarningNoticeGzry;

    @Resource
    private TraceSysCheckRouter traceSysCheckRouter;

    @Override
    public void noticeJzry(List<Position> positions) {
        positions = this.filter(positions);
        Map<String, MessageNoticeResultDTO> notices = positionWarningNoticeJzry.notice(positions);
        //位置确认核查
        traceSysCheckRouter.noticeJzry(positions, notices);
    }

    @Override
    public void noticeGzry(List<Position> positions) {
        positions = this.filter(positions);
        positionWarningNoticeGzry.notice(positions,this);
    }

    /**
     * 排除掉位置确认，避免循环发通知
     */
    private List<Position> filter(List<Position> positions) {
        return positions.stream()
                .filter(e -> !ReportType.TRACK_CHECK.getCode().equals(e.getReportType()))
                .collect(Collectors.toList());
    }
}
